home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c_course.zip / READGOOD.C < prev    next >
C/C++ Source or Header  |  1989-12-30  |  656b  |  25 lines

  1. /*      READGOOD.C   fscanf()  do/while but EOF test inside loop   */
  2.  
  3. /* Notice that fscanf like fget has a c= in front of it. So the whole
  4. fscanf function takes on the value of all characters in a stream while
  5. it fills up the array identified in the third parameter.  */
  6.  
  7. #include "stdio.h"
  8.  
  9. main()
  10. {
  11. FILE *fp1;
  12. char oneword[100];
  13. int c;
  14.  
  15.    fp1 = fopen("TENLINES.TXT","r");
  16.  
  17.    do {
  18.       c = fscanf(fp1,"%s",oneword); /* got one word from the file */
  19.       if (c != EOF)
  20.          printf("%s\n",oneword);    /* display it on the monitor  */
  21.    } while (c != EOF);              /* repeat until EOF           */
  22.  
  23.    fclose(fp1);
  24. }
  25.